class SlideManager {
  constructor() {
    this.currentSlideId = null
    this.listeners = new Map()
  }

  // 开始滑动
  startSlide(slideId) {
    console.log('开始滑动:', slideId, '当前:', this.currentSlideId)
    
    // 如果已经有其他项目在滑动，先关闭它
    if (this.currentSlideId && this.currentSlideId !== slideId) {
      console.log('关闭其他滑动:', this.currentSlideId)
      this.closeCurrentSlide()
    }
    this.currentSlideId = slideId
  }

  // 关闭当前滑动
  closeCurrentSlide() {
    if (this.currentSlideId) {
      console.log('触发关闭滑动:', this.currentSlideId)
      // 触发关闭事件
      uni.$emit('closeSlide', this.currentSlideId)
      this.currentSlideId = null
    }
  }

  // 强制关闭所有滑动
  closeAllSlides() {
    console.log('强制关闭所有滑动')
    if (this.currentSlideId) {
      uni.$emit('closeSlide', this.currentSlideId)
    }
    this.currentSlideId = null
  }

  // 结束滑动
  endSlide(slideId) {
    console.log('结束滑动:', slideId)
    if (this.currentSlideId === slideId) {
      this.currentSlideId = null
    }
  }

  // 检查是否应该关闭当前滑动
  shouldCloseCurrent(slideId) {
    return this.currentSlideId && this.currentSlideId !== slideId
  }

  // 获取当前滑动状态
  getCurrentSlideId() {
    return this.currentSlideId
  }
}

export default new SlideManager()